#ifndef MESSAGEPACKAGE_H
#define MESSAGEPACKAGE_H

#include <QJsonDocument>
#include <QJsonObject>
#include <QTcpSocket>
#include <QByteArray>

class messagePackage
{
public:
    enum Type{
        Register        = 0x00,
        Login           = 0x01,
        OnlineUser      = 0x02,
        PrivateChat     = 0x03,
        AllUsers        = 0x04,
        Group           = 0x05,
        GroupChat       = 0x06,
        InviteGroup     = 0x07,
        UploadFile      = 0x08,
        AllFile         = 0x09,
        DownloadFile    = 0x0A,
        GroupFile       = 0x0B,
        Meeting         = 0x0C,
        InviteMeeting   = 0x0D,
        UpdateMeeting   = 0x0E,
        QuitMeetintg    = 0x0F,
        ClearMeeting    = 0x10
    };
    messagePackage();
    void setMessage(const QJsonObject &value);
    void setMessage(const QByteArray byte);
    void setMessage(const QString str);

    void setType(messagePackage::Type type);
    messagePackage::Type type() const;

    void setUserName(QString name);
    QString userName();

    void setUserPassword(QString pswd);
    QString userPassword();

    QByteArray toByteArray() const;

    void setRet(bool ret);
    bool ret() const;

    void setRetInt(int value);
    int retInt() const;

    void setOnlineUsers(QStringList users);
    QStringList OnlinUsers() const;

    void setSender(QString sender);
    QString sender() const;

    void setReceiver(QString receiver);
    QString receiver() const;

    void setInfo(QString info);
    QString info() const;

    void setTime(QString time);
    QString time() const;

    void setAllUsers(QStringList users);
    QStringList allUsers() const;

    void setGroupName(QString name);
    QString groupName() const;

    void setFileName(QString name);
    QString fileName() const;

    void setFileData(QByteArray data);
    QByteArray fileData() const;

    void setAllFile(QStringList fileName);
    QStringList allFile() const;

    void setMeetingName(QString meetingName);
    QString meetingName() const;

    void setIp(QString ip);
    QString ip() const;

    void setPort(quint16 port);
    quint16 port() const;

    static void sendMessage(const messagePackage* msg,QTcpSocket* socket);
    static messagePackage recvMessage(QTcpSocket* socket);

private:
    QJsonObject message;

};

#endif // MESSAGEPACKAGE_H
